package org.example.commerce.dao;

import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;
import org.example.commerce.dao.entity.Goods;
import org.example.commerce.dao.vo.ProduceWithCategoryVo;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@org.apache.ibatis.annotations.Mapper
public interface GoodsMapper extends Mapper<Goods> {
    @Results({
            @Result( column = "id",jdbcType = JdbcType.INTEGER, property = "id", id = true),
            @Result(column="name",jdbcType=JdbcType.VARCHAR,property="name"),
            @Result(column="price",jdbcType=JdbcType.VARCHAR,property="price"),
            @Result(column="create_time" ,jdbcType=JdbcType.TIMESTAMP,property="createTime"),
            @Result(column="img_url" ,jdbcType=JdbcType.VARCHAR,property="imgUrl"),
            @Result(column="categoryId" ,jdbcType=JdbcType.INTEGER, property="categoryId"),
            @Result(column="category" ,jdbcType=JdbcType.VARCHAR, property="category")
    })

    @Select({
            "SELECT t.id , t.name , t.price , t.create_time , t.img_url , c.name category FROM tab_goods t  LEFT JOIN tab_category c ON t.category_id =c.id"
    })
    List<ProduceWithCategoryVo> selectProduceWithCategory();


}
